/**
 * @date 2006-7-18
 */

package org.nanhill.xmlro.gsp;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.nanhill.xmlro.gsp.client.DefaultGspAgent;
import org.nanhill.xmlro.gsp.client.GspAgent;

/**
 * @author alin [xalinx at gmail dot com]
 * @date 2006-7-18
 */
public class ImportDataSample {

	private static long getRetcode(Map result) {
		Map map = (Map) result;
		return (Long) map.get("retcode");
	}

	/**
	 * @param args
	 * @throws GspException
	 */
	public static void main(String[] args) {
		// create agent bind with sls module name
		GspAgent importAgent = new DefaultGspAgent("hawaii.kernel.sls");
		try {
			// ============ centaurus.impservice ============================
			// ------------- sls ------------------------
			// add sls target
			importAgent.addSLSTarget("192.168.3.6", 2001);
			// set gsp service name and version
			importAgent.setServiceType("centaurus.impservice", "1");
			importAgent.locate();

			// ------------- import data -------------------
			Map<String, Object> importData = new HashMap<String, Object>();
			importData.put("class#", 3L);
			importData
					.put(
							"message",
							"<record><msgtype>QYDW</msgtype><bigclass>FZ</bigclass><littleclass>[纺织成品]  "
									+ "</littleclass><keyword>家私寝具</keyword><name>杭州新雅家私制造有限公司</name><namecode>xyjszs</namecode>"
									+ "<addr>余杭区良渚镇良渚路22号</addr><addrcode>lz</addrcode><phone>88778877</phone></record>");
			importData.put("subject", "房源:alinTesthotel");
			// importData.put("url", "hulian.qiyexinxi.1145465667");
			// -- 可选
			importData.put("date", System.currentTimeMillis());
			importData.put("expire", System.currentTimeMillis() + 100000);
			importData.put("gid", "1.uu");
			// --
			// do gsp service by service command and transport object
			Map result = (Map) importAgent.doService("importData", importData);
			System.out.println(ImportDataSample.getRetcode(result));
			// ----------- close ------------
			importAgent.close();
		} catch (GspException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
